package com.twu.biblioteca;

import com.google.common.base.Function;

import java.util.List;

import static com.google.common.collect.FluentIterable.from;
import static com.google.common.collect.Lists.newArrayList;

public class ViewMoviesHandler implements Handler {
    public static final String MOVIE_LIST_HEADER = "Movie  Year    Director    Rating";
    private List<Movie> movies = newArrayList();

    public ViewMoviesHandler() {
        for (int i = 0; i < 15; i++) {
            Movie movie = new Movie("name" + String.valueOf(i), 1990 + i, "director" + String.valueOf(i), String.valueOf(1 + i));
            if (i > 9) {
                movie.setRating("N/A");
            }
            movies.add(movie);
        }
    }
    @Override
    public List<String> handle() {
        List<String> movieList = newArrayList();
        movieList.add(MOVIE_LIST_HEADER);
        List<String> movies = from(this.movies).transform(new Function<Movie, String>() {
            @Override
            public String apply(Movie movie) {
                return movie.toString();
            }
        }).toList();
        movieList.addAll(movies);
        return movieList;
    }
}
